<template>

    <routerLink to="/main/add"><el-button type="primary">➕ 设备入库</el-button>
    </routerLink>
    <el-table :data="tableData" style="width: 100%" :row-class-name="tableRowClassName">
        <el-table-column prop="id" label="序号" width="80" />
        <el-table-column prop="name" label="物品名称" width="180" />
        <el-table-column prop="model" label="型号" />
        <el-table-column prop="type" label="类型" />
        <el-table-column prop="num" label="数量" width="80" />
        <el-table-column prop="state" label="状态" />
        <el-table-column prop="date" label="入库时间" width="180" />
        <el-table-column prop="note" label="备注" />
        <el-table-column fixed="right" label="Operations" width="120">
            <template #default="scope">
                <el-button link type="primary" size="small" @click="handleClick(scope.row)">编辑</el-button>
            </template>
        </el-table-column>
    </el-table>
    <Edit v-if="isShow" :msg="msg" />
</template>

<script lang="ts" setup>
import {getFile} from '../../api/file'
import { ref,onMounted, reactive } from 'vue'
import Edit from './Edit.vue'
interface User {
    date: string
    name: string
    address: string
}

const tableRowClassName = ({
    row,
    rowIndex,
}: {
    row: User
    rowIndex: number
}) => {
    if (rowIndex === 1) {
        return 'warning-row'
    } else if (rowIndex === 3) {
        return 'success-row'
    }
    return ''
}
let isShow = ref(false)
let msg = ref({ isShow: false, data: [], valueChanged: () => { } })
const handleClick = (data) => {
    isShow.value = true
    msg.value = {
        data: data,
        isShow: isShow.value,
        valueChanged:()=>{
            isShow.value = false
        }
    }
}

let tableData = ref()
onMounted(async()=>{
    const res = await getFile()
    tableData.value = res.data
})
</script>

<style>
.el-table .warning-row {
    --el-table-tr-bg-color: var(--el-color-warning-light-9);
}

.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-light-9);
}
</style>
